<template>
    <div style="margin: 10px 0;">
        <el-select v-model="searchStatus" placeholder="请选择审核情况">
            <el-option label="所有" value="" @click="checkTeaching()"></el-option>
            <el-option label="审核中" value="审核中" @click="checkTeaching()"></el-option>
            <el-option label="审核通过" value="审核通过" @click="checkTeaching()"></el-option>
            <el-option label="审核失效" value="审核失效" @click="checkTeaching()"></el-option>
            <el-option label="未提交" value="未提交" @click="checkTeaching()"></el-option>
        </el-select>
        <el-input v-model="searchAwardName" placeholder="按奖项名称搜索" style=" width: 20%;" clearable></el-input>
        <el-input v-model="searchAchievementName" placeholder="按成果名称搜索" style=" width: 20%;" clearable></el-input>
        <el-button style="margin-left:5px ;" @click="checkTeaching()">
            <el-icon>
                <search />
            </el-icon><span style="margin-left: 5px;">查询</span>
        </el-button>
        <el-button type="primary" style="margin-left:30px ;" @click="checkAdd()">
            <el-icon>
                <document-add />
            </el-icon><span style="margin-left: 5px;">添加</span>
        </el-button>
        <el-button type="primary" @click="dialogExcel = true">导入科研成果信息</el-button>
        <el-table :data="tableData" stripe style="width: 100%;margin-top: 10px;">
            <el-table-column prop="id" label="ID" sortable />
            <el-table-column prop="awardName" label="奖项名称" />
            <el-table-column prop="achievementName" label="成果名称" />
            <el-table-column prop="achievementLevel" label="级别" />
            <el-table-column label="状态">
                <template #default="scope">
                    <el-tag vclass="ml-2" v-if="scope.row.status == '审核通过'">{{scope.row.status}}</el-tag>
                    <el-tag vclass="ml-2" type="warning" v-else-if="scope.row.status == '审核中'">{{scope.row.status}}
                    </el-tag>
                    <el-tag vclass="ml-2" type="info" v-else-if="scope.row.status == '未提交'">{{scope.row.status}}
                    </el-tag>
                    <el-tag vclass="ml-2" type="danger" v-else>{{scope.row.status}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="inputPeople" label="录入人" />
            <el-table-column label="操作">
                <template #default="scope">
                    <el-button type="text" @click="checkUp(scope.row)">信息详情</el-button>
                    <el-button type="text" @click="dealFile(scope.row)">附件详情</el-button>
                    <el-popconfirm title="确定提交审核吗？" v-if="scope.row.status == '未提交'||scope.row.status == '审核失效'" @confirm="dealStatus(scope.row,'审核中')">
                         <template #reference>
                             <el-button type="text" >提交审核</el-button>
                         </template>
                     </el-popconfirm>
                     <el-popconfirm title="确定退回修改吗？" v-if="scope.row.status == '审核中'" @confirm="dealStatus(scope.row,'未提交')">
                          <template #reference>
                              <el-button type="text" >退回修改</el-button>
                          </template>
                      </el-popconfirm>
                    <el-popconfirm title="这些内容确定删除吗？" v-if="scope.row.status == '未提交' ||scope.row.status == '审核失效'" @confirm="deleteFile(scope.row)">
                        <template #reference>
                            <el-button type="text" >删除</el-button>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <div class="demo-pagination-block">
            <div style="float: right;">
                <el-pagination :currentPage="current" :page-sizes="[10,20,30]" :page-size=page
                    layout="sizes, prev, pager, next,total,jumper" :total=firstTotal @size-change="handleSize"
                    @current-change="handleCurrent">
                </el-pagination>
            </div>
        </div>

        <el-dialog v-model="dialogAddResearch" title="录入科研成果奖励" width="60%" center>
            <el-form ref="researchAchievements" :model="researchAchievements" :rules="rules" label-width="200px"
                class="demo-ruleForm" :size="formSize">
                <el-form-item label="奖项名称" prop="awardName">
                    <el-input v-model="researchAchievements.awardName" placeholder="请输入奖项名称"></el-input>
                </el-form-item>

                <el-form-item label="成果名称" prop="achievementName">
                    <el-input v-model="researchAchievements.achievementName" placeholder="请输入成果名称"></el-input>
                </el-form-item>

                <el-form-item label="证书编号" prop="certificateNumber"  >
                    <el-input v-model="researchAchievements.certificateNumber" placeholder="请输入证书编号"></el-input>
                </el-form-item>

                <el-form-item label="来源(发奖单位)">
                    <el-input v-model="researchAchievements.sources" placeholder="请输入来源(发奖单位)"></el-input>
                </el-form-item>


                <el-form-item label="级别" prop="achievementLevel">
                    <el-select v-model="researchAchievements.achievementLevel" placeholder="请选择级别">
                        <el-option label="国家级" value="国家级"></el-option>
                        <el-option label="国家部委级" value="国家部委级"></el-option>
                        <el-option label="省级" value="省级"></el-option>
                        <el-option label="地厅级" value="地厅级"></el-option>
                        <el-option label="校级" value="校级"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="等级" prop="grade">
                    <el-select v-model="researchAchievements.grade" placeholder="请选择获奖等级">
                        <el-option label="特等奖" value="特等奖"></el-option>
                        <el-option label="特别奉献奖" value="特别奉献奖"></el-option>
                        <el-option label="一等奖" value="一等奖"></el-option>
                        <el-option label="二等级" value="二等级"></el-option>
                        <el-option label="三等奖" value="三等奖"></el-option>
                        <el-option label="四等奖" value="四等奖"></el-option>
                        <el-option label="优秀奖" value="优秀奖"></el-option>
                        <el-option label="金奖" value="金奖"></el-option>
                        <el-option label="银奖" value="银奖"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="获奖时间" required>
                    <el-col :span="11">
                        <el-form-item prop="awardTime">
                            <el-date-picker v-model="researchAchievements.awardTime" type="date" placeholder="选择日期"
                                style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-form-item>

                <el-form-item label="本校排名">
                    <el-input-number :min="1" controls-position="right" v-model.number="researchAchievements.rankingCompany"
                        style="width: 100px"></el-input-number>
                </el-form-item>

                <el-form-item label="本单位是否主要完成单位" prop="completionCompany">
                    <el-radio-group v-model="completionCompany">
                        <el-radio label="是"></el-radio>
                        <el-radio label="否"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="本单位是否主持单位" prop="unitInCharge">
                    <el-radio-group v-model="unitInCharge">
                        <el-radio label="是"></el-radio>
                        <el-radio label="否"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="录入人">
                    {{researchAchievements.inputPeople}}
                </el-form-item>

                <el-form-item label="支撑材料">
                    <el-upload ref="upload" class="upload-demo" drag action="#" :http-request="uploadFile">
                        <el-icon class="el-icon--upload">
                            <upload-filled />
                        </el-icon>
                        <div class="el-upload__text">
                            拖放文件 <em>上传文件</em>
                        </div>
                    </el-upload>
                </el-form-item>




                <el-form-item label="参与人员">
                    <div>
                        <el-button size="small" type="primary" @click="addAccount()">选择本单位人员</el-button>
                        <el-button size="small" @click="addStudent()">增加学生或外单位人员</el-button>
                        <el-button size="small" type="primary" @click="addOneSelf()">增加本人</el-button>
                    </div>
                    <div style="margin-top: 10px;">
                        <el-table :data="researchAchievements.participants" max-height="250" style="width: 100%">
                            <el-table-column label="排序">
                                <template #default="scope">
                                    <el-input-number :min="1" controls-position="right"
                                        v-model.number="scope.row.sortNumber" style="width: 100px"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column label="姓名">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.participantName}}</span>
                                    <el-input v-model="scope.row.participantName" placeholder="请输入姓名" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="参与方式">
                                <template #default="scope">
                                    <el-input v-model="scope.row.participationMode" placeholder="请输入参与方式"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="工作单位">
                                <template #default="scope">
                                    <el-input v-model="scope.row.workPlace" v-if="scope.row.usersId!=null" disabled>
                                    </el-input>
                                    <el-input v-model="scope.row.workPlace" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="类别">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.category}}</span>
                                    <el-select v-model="scope.row.category" placeholder="类别" v-else>
                                        <el-option label="老师" value="老师"></el-option>
                                        <el-option label="学生" value="学生"></el-option>
                                        <el-option label="外单位" value="外单位"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template #default="scope">
                                    <el-button style="color: red;" type="text" @click="deleteOne(scope.$index)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button size="large" type="primary" @click="submitAddresearchAchievements('researchAchievements')">保存科研成果奖励
                    </el-button>
                </el-form-item>

            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogAddAccount" title="录入科研成果奖励" width="30%" center>
            <el-select v-model="searchRoles" style=" width: 20%;" placeholder="请选择角色类别">
                <el-option label="所有" value="" @click="checkRoles()"></el-option>
                <el-option label="管理员" value="管理员" @click="checkRoles()"></el-option>
                <el-option label="老师" value="老师" @click="checkRoles()"></el-option>
                <el-option label="研究生" value="研究生" @click="checkRoles()"></el-option>
            </el-select>
            <el-input v-model="searchName" placeholder="按名搜索" style=" width: 20%;" clearable></el-input>
            <el-button style="margin-left:5px ;" @click="checkRoles()">
                <el-icon>
                    <search />
                </el-icon><span style="margin-left: 5px;">查询</span>
            </el-button>
            <el-button style="margin-left:5px ;" type="primary" @click="addListparticipants()">
                <span>添加</span>
            </el-button>
            <div style="margin-top: 10px;">
                <el-table ref="multipleTableRef" :data="AccountTableData" @selection-change="handleSelectionChange"
                    @row-click="textRowClick" stripe style="width: 100%">
                    <el-table-column type="selection" width="55" />
                    <el-table-column prop="participantName" label="姓名" />
                    <el-table-column prop="workPlace" label="工作单位" />
                    <el-table-column prop="category" label="类别" />
                </el-table>
            </div>
            <div class="demo-pagination-block">
                <div style="float: right;">
                    <el-pagination :currentPage="currentPage" :page-size=pageSize
                        layout="prev, pager, next,total,jumper" :total=total @current-change="handleCurrentChange">
                    </el-pagination>
                </div>
            </div>

            <!-- 多留空间好看 -->
            <div style="margin-top: 10px;"></div>
        </el-dialog>

        <el-dialog v-model="dialogUpResearch" title="科研成果奖励详情" width="60%" center>
            <el-form ref="researchAchievements" :model="researchAchievements" :rules="rules" label-width="200px"
                class="demo-ruleForm" :size="formSize">
                <el-form-item label="奖项名称" prop="awardName">
                    <el-input v-model="researchAchievements.awardName" placeholder="请输入奖项名称"></el-input>
                </el-form-item>

                <el-form-item label="成果名称" prop="achievementName">
                    <el-input v-model="researchAchievements.achievementName" placeholder="请输入成果名称"></el-input>
                </el-form-item>

                <el-form-item label="证书编号" prop="certificateNumber">
                    <el-input v-model="researchAchievements.certificateNumber" placeholder="请输入证书编号"></el-input>
                </el-form-item>

                <el-form-item label="来源(发奖单位)">
                    <el-input v-model="researchAchievements.sources" placeholder="请输入来源(发奖单位)"></el-input>
                </el-form-item>


                <el-form-item label="级别" prop="achievementLevel">
                    <el-select v-model="researchAchievements.achievementLevel" placeholder="请选择级别">
                        <el-option label="国家级" value="国家级"></el-option>
                        <el-option label="国家部委级" value="国家部委级"></el-option>
                        <el-option label="省级" value="省级"></el-option>
                        <el-option label="地厅级" value="地厅级"></el-option>
                        <el-option label="校级" value="校级"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="等级" prop="grade">
                    <el-select v-model="researchAchievements.grade" placeholder="请选择获奖等级">
                        <el-option label="特等奖" value="特等奖"></el-option>
                        <el-option label="特别奉献奖" value="特别奉献奖"></el-option>
                        <el-option label="一等奖" value="一等奖"></el-option>
                        <el-option label="二等级" value="二等级"></el-option>
                        <el-option label="三等奖" value="三等奖"></el-option>
                        <el-option label="四等奖" value="四等奖"></el-option>
                        <el-option label="优秀奖" value="优秀奖"></el-option>
                        <el-option label="金奖" value="金奖"></el-option>
                        <el-option label="银奖" value="银奖"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="获奖时间" required>
                    <el-col :span="11">
                        <el-form-item prop="awardTime">
                            <el-date-picker v-model="researchAchievements.awardTime" type="date" placeholder="选择日期"
                                style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-form-item>

                <el-form-item label="本校排名">
                    <el-input-number :min="1" controls-position="right" v-model.number="researchAchievements.rankingCompany"
                        style="width: 100px"></el-input-number>
                </el-form-item>

                <el-form-item label="本单位是否主要完成单位" prop="completionCompany">
                    <el-radio-group v-model="completionCompany">
                        <el-radio label="是"></el-radio>
                        <el-radio label="否"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="本单位是否主持单位" prop="unitInCharge">
                    <el-radio-group v-model="unitInCharge">
                        <el-radio label="是"></el-radio>
                        <el-radio label="否"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="录入人">
                    {{researchAchievements.inputPeople}}
                </el-form-item>

                <el-form-item label="参与人员">
                    <div v-if="cheackOrDeal">
                        <el-button size="small" type="primary" @click="addAccount()">选择本单位人员</el-button>
                        <el-button size="small" @click="addStudent()">增加学生或外单位人员</el-button>
                        <span>（对参与人员的修改可能会很慢）</span>
                    </div>
                    <div style="margin-top: 10px;">
                        <el-table :data="researchAchievements.participants" max-height="250" style="width: 100%">
                            <el-table-column label="排序">
                                <template #default="scope">
                                    <el-input-number :min="1" controls-position="right"
                                        v-model.number="scope.row.sortNumber" style="width: 100px"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column label="姓名">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.participantName}}</span>
                                    <el-input v-model="scope.row.participantName" placeholder="请输入姓名" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="参与方式">
                                <template #default="scope">
                                    <el-input v-model="scope.row.participationMode" placeholder="请输入参与方式"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="工作单位">
                                <template #default="scope">
                                    <el-input v-model="scope.row.workPlace" v-if="scope.row.usersId!=null" disabled>
                                    </el-input>
                                    <el-input v-model="scope.row.workPlace" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="类别">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.category}}</span>
                                    <el-select v-model="scope.row.category" placeholder="类别" v-else>
                                        <el-option label="老师" value="老师"></el-option>
                                        <el-option label="学生" value="学生"></el-option>
                                        <el-option label="外单位" value="外单位"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template #default="scope">
                                    <el-button style="color: red;" type="text" @click="deleteOne(scope.$index)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form-item>
                <el-form-item v-if="cheackOrDeal">
                    <el-button size="large" type="primary" @click="submitUpresearchAchievements('researchAchievements')">修改科研成果奖励
                    </el-button>
                </el-form-item>

            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogDealFile" title="附件详情" width="30%" center>
            <div style="text-align: center;">
                <el-button type="success" @click="getFile">下载附件</el-button>
                <el-divider style="border-width: 3px;"></el-divider>

                <el-upload ref="updataFile" class="upload-demo" drag action="#" :http-request="UpFile" v-if="cheackOrDeal">
                    <el-icon class="el-icon--upload">
                        <upload-filled />
                    </el-icon>
                    <div class="el-upload__text">
                        拖放文件 <em>修改文件</em>
                    </div>
                </el-upload>
            </div>
        </el-dialog>
        
        <el-dialog v-model="dialogExcel" title="导入科研成果信息" width="30%" center>
            <div style="text-align: center;">
                <el-button type="success" @click="getExcelType">下载Excel模板</el-button>
                <el-divider style="border-width: 3px;"></el-divider>
        
                <el-upload class="upload-demo" drag ref="uploadExcel" action="#"
                    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                    :http-request="uploadFileExcel">
                    <el-icon class="el-icon--upload">
                        <upload-filled />
                    </el-icon>
                    <div class="el-upload__text">
                        拖放文件 <em>上传文件</em>
                    </div>
                </el-upload>
            </div>
        </el-dialog>


    </div>
</template>

<script>
    import {
        ref,
        reactive,
        computed,
        watch
    } from 'vue'
    import {
        UploadFilled,
        InfoFilled 
    } from '@element-plus/icons-vue'
    import request from '@/utils/request'
    import {
        ElMessage
    } from 'element-plus'
    export default {
        name: '',
        data() {
            return {
                tableData: [],
                current: 1,
                page: 10,
                firstTotal: '',
                currentPage: 1, // 用户当前页
                total: '', // 总页数
                pageSize: 10, // 每页要展示数据条数
                AccountTableData: [], // 接收后台的总数据
                accountCache: [],
                dialogAddResearch: false,
                dialogAddAccount: false,
                dialogUpResearch: false,
                dialogDealFile: false,
                dialogExcel: false,
                searchName: '',
                searchRoles: '',
                searchStatus: '',
                searchAwardName: '',
                searchAchievementName: '',
                loadAddress: '',
                unitInCharge: '',
                completionCompany: '',
                cheackOrDeal: false,
                oneself: {
                    id: '',
                    sortNumber: '',
                    participantName: '',
                    participationMode: '',
                    workPlace: '',
                    category: '',
                    usersId: '',
                },
                researchAchievements: {
                    id: '',
                    awardName: '',
                    achievementName: '',
                    certificateNumber: '',
                    sources: '',
                    achievementLevel: '',
                    grade: '',
                    awardTime: '',
                    inputPeople: '',
                    completionCompany: '',
                    unitInCharge: '',
                    rankingCompany: 1,
                    supportingMaterials: '',
                    status: '',
                    userId: '',
                    participants: [{
                        // id: '',
                        // sortNumber: '',
                        // participantName: '',
                        // participationMode: '',
                        // workPlace: '',
                        // category: ''
                    }],
                },
                rules: {
                    awardTime: [{
                        type: 'date',
                        required: true,
                        message: '请选择出版/发表日期',
                        trigger: 'change',
                    }, ],
                    certificateNumber:{
                        required: true,
                        message: '请输入证书编号',
                        trigger: 'blur',
                    },
                    awardName: {
                        required: true,
                        message: '请输入奖项名称',
                        trigger: 'blur',
                    },
                    achievementName: {
                        required: true,
                        message: '请输入成果名称',
                        trigger: 'blur',
                    },
                    achievementLevel: {
                        required: true,
                        message: '请选择级别',
                        trigger: 'change',
                    },
                    grade: {
                        required: true,
                        message: '请选择获奖等级',
                        trigger: 'change',
                    }
                    // unitInCharge: {
                    //     required: true,
                    //     message: '请选择',
                    //     trigger: 'change',
                    // },
                    // completionCompany: {
                    //     required: true,
                    //     message: '请选择',
                    //     trigger: 'change',
                    // },

                }
            }
        },
        methods: {
            checkTeaching() {
                this.current = 1;
                this.load()
            },
            checkAdd() {
                this.researchAchievements.id = ''
                this.researchAchievements.awardName = ''
                this.researchAchievements.achievementName = ''
                this.researchAchievements.certificateNumber = ''
                this.researchAchievements.sources = ''
                this.researchAchievements.achievementLevel = ''
                this.researchAchievements.grade = ''
                this.researchAchievements.awardTime = ''
                this.researchAchievements.inputPeople = ''
                this.researchAchievements.completionCompany = ''
                this.researchAchievements.unitInCharge = ''
                this.researchAchievements.rankingCompany = 1
                this.researchAchievements.supportingMaterials = ''
                this.researchAchievements.status = ''
                this.researchAchievements.userId = ''
                this.researchAchievements.participants = []
                this.completionCompany = ''
                this.unitInCharge = ''
                this.oneself = ''
                request({
                    url: '/accounts/getSimpleAccount',
                    headers: {
                        isToken: true
                    },
                    timeout: 20000,
                    method: 'get',
                    params: {}
                }).then((res) => {
                    res.data.user.sortNumber = 1;
                    this.researchAchievements.participants.push(res.data.user);
                    this.researchAchievements.inputPeople = res.data.user.participantName
                    this.oneself = res.data.user;
                })
                this.dialogAddResearch = true;
            },
            checkUp(row) {
                this.researchAchievements.id = row.id
                this.researchAchievements.awardName = row.awardName
                this.researchAchievements.achievementName = row.achievementName
                this.researchAchievements.certificateNumber = row.certificateNumber
                this.researchAchievements.sources = row.sources
                this.researchAchievements.achievementLevel = row.achievementLevel
                this.researchAchievements.grade = row.grade
                this.researchAchievements.awardTime = row.awardTime
                this.researchAchievements.inputPeople = row.inputPeople
                this.researchAchievements.rankingCompany = row.rankingCompany
                this.researchAchievements.supportingMaterials = row.supportingMaterials
                this.researchAchievements.status = row.status
                this.researchAchievements.userId = row.userId
                this.researchAchievements.participants = row.participants
                this.researchAchievements.completionCompany = row.completionCompany
                if (row.completionCompany) this.completionCompany = '是';
                else this.completionCompany = '否';
                this.researchAchievements.unitInCharge = row.unitInCharge
                if (row.unitInCharge) this.unitInCharge = '是';
                else this.unitInCharge = '否';
                if (row.status == '未提交' || row.status == '审核失效') this.cheackOrDeal = true;
                else this.cheackOrDeal = false;
                this.dialogUpResearch = true
            },
            addAccount() {
                this.currentPage = 1;
                this.pageSize = 10;
                this.total = '';
                this.accountLoad();
                this.dialogAddAccount = true;
            },
            accountLoad() {
                request({
                    url: '/accounts/getAllSimpleAccount',
                    headers: {
                        isToken: false
                    },
                    timeout: 20000,
                    method: 'get',
                    params: {
                        currentPage: this.currentPage,
                        pageSize: this.pageSize,
                        searchName: this.searchName,
                        searchRoles: this.searchRoles
                    }
                }).then((res) => {
                    this.total = res.data.total;
                    this.AccountTableData = res.data.account;
                })
            },
            checkRoles() {
                this.currentPage = 1;
                this.accountLoad();
            },
            handleSelectionChange(selection) {
                this.accountCache = selection
            },
            dealFile(row) {
                this.researchAchievements.supportingMaterials = row.supportingMaterials;
                this.researchAchievements.id = row.id;
                if (row.status == '未提交' || row.status == '审核失效') this.cheackOrDeal = true;
                else this.cheackOrDeal = false;
                this.dialogDealFile = true;
            },
            uploadFile(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: false
                    }
                };
                request.post('/researchAchievements/fileCache', formData, config).then((res) => {
                    this.researchAchievements.supportingMaterials = res.data.saveName;
                    ElMessage({
                        showClose: true,
                        message: '上传成功',
                        center: true,
                        type: 'success'
                    })
                });
            },
            addListparticipants() {
                for (let i = 0; i < this.accountCache.length; i++) {
                    if (this.checkRepeatName(this.accountCache[i])) {
                        this.accountCache[i].sortNumber = this.researchAchievements.participants.length + 1;
                        this.researchAchievements.participants.push(this.accountCache[i]);
                    }
                }
                this.dialogAddAccount = false;
            },
            checkRepeatName(object) {
                for (let i = 0; i < this.researchAchievements.participants.length; i++) {
                    if (this.researchAchievements.participants[i].usersId == object.usersId) {
                        ElMessage({
                            showClose: true,
                            message: object.participantName + '已在人员列表中',
                            center: true,
                            type: 'warning'
                        })
                        return false;
                    }
                }
                return true;
            },
            addOneSelf() {
                if (this.checkRepeatName(this.oneself)) {
                    this.oneself.sortNumber = this.researchAchievements.participants.length + 1
                    this.researchAchievements.participants.push(this.oneself);
                }
            },
            deleteOne(index) {
                //通过下标删除距离一个位置的内容
                this.researchAchievements.participants.splice(index, 1);
            },
            addStudent() {
                this.researchAchievements.participants.push({
                    id: '',
                    sortNumber: this.researchAchievements.participants.length + 1,
                    participantName: '',
                    participationMode: '',
                    workPlace: '',
                    category: ''
                });
            },
            submitAddresearchAchievements(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if(this.researchAchievements.participants.length ==0){
                            ElMessage({
                                showClose: true,
                                message: '请添加参与人员，不然无法添加数据',
                                center: true,
                                type: 'error'
                            })
                        }else{
                        if (this.completionCompany == '是') this.researchAchievements
                            .completionCompany = true;
                        else this.researchAchievements.completionCompany = false;
                        if (this.unitInCharge == '是') this.researchAchievements.unitInCharge = true;
                        else this.researchAchievements.unitInCharge = false;
                        request({
                            url: '/researchAchievements',
                            headers: {
                                isToken: true
                            },
                            method: 'post',
                            timeout: 20000,
                            data: this.researchAchievements
                        }).then(() => {
                            this.load();
                            this.dialogAddResearch = false;
                            this.$refs['upload'].clearFiles('ready')
                            ElMessage({
                                showClose: true,
                                message: '添加成功',
                                center: true,
                                type: 'success'
                            })
                        });
                        }
                    } else {
                        console.log('error submit!!')
                        return false
                    }
                })
            },
            submitUpresearchAchievements(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if(this.researchAchievements.participants.length ==0){
                            ElMessage({
                                showClose: true,
                                message: '请添加参与人员，不然无法添加数据',
                                center: true,
                                type: 'error'
                            })
                        }else{
                        if (this.completionCompany == '是') this.researchAchievements
                            .completionCompany = true;
                        else this.researchAchievements.completionCompany = false;
                        if (this.unitInCharge == '是') this.researchAchievements.unitInCharge = true;
                        else this.researchAchievements.unitInCharge = false;
                        request({
                            url: '/researchAchievements',
                            headers: {
                                isToken: false
                            },
                            method: 'put',
                            timeout: 20000,
                            data: this.researchAchievements
                        }).then(() => {
                            this.dialogUpResearch = false;
                            this.load();
                            ElMessage({
                                showClose: true,
                                message: '修改成功',
                                center: true,
                                type: 'success'
                            })
                        });
                        }
                    } else {
                        console.log('error submit!!')
                        return false
                    }
                });
            },
            deleteFile(row) {
                this.researchAchievements.id = row.id
                this.researchAchievements.awardName = row.awardName
                this.researchAchievements.achievementName = row.achievementName
                this.researchAchievements.certificateNumber = row.certificateNumber
                this.researchAchievements.sources = row.sources
                this.researchAchievements.achievementLevel = row.achievementLevel
                this.researchAchievements.grade = row.grade
                this.researchAchievements.awardTime = row.awardTime
                this.researchAchievements.inputPeople = row.inputPeople
                this.researchAchievements.completionCompany = row.completionCompany
                this.researchAchievements.unitInCharge = row.unitInCharge
                this.researchAchievements.rankingCompany = row.rankingCompany
                this.researchAchievements.supportingMaterials = row.supportingMaterials
                this.researchAchievements.status = row.status
                this.researchAchievements.userId = row.userId
                this.researchAchievements.participants = row.participants
                request({
                    url: '/researchAchievements',
                    headers: {
                        isToken: false
                    },
                    method: 'delete',
                    timeout: 20000,
                    data: this.researchAchievements,
                }).then(() => {
                    this.load()
                    ElMessage({
                        showClose: true,
                        message: '删除成功',
                        center: true,
                        type: 'success'
                    })
                })
            },
            load() {
                request({
                    url: '/researchAchievements',
                    headers: {
                        isToken: true
                    },
                    method: 'get',
                    timeout: 20000,
                    params: {
                        current: this.current,
                        page: this.page,
                        searchStatus: this.searchStatus,
                        searchAwardName: this.searchAwardName,
                        searchAchievementName: this.searchAchievementName,
                    }
                }).then((res) => {
                    this.tableData = res.data.tableData;
                    this.firstTotal = res.data.total;
                    this.loadAddress = res.data.loadAddress;
                });
            },
            handleSize(pageSize) {
                this.page = pageSize;
                this.current = 1;
                this.load();
            },
            handleCurrent(currentPage) {
                this.current = currentPage;
                this.load();
            },
            getFile() {
                request({
                    url: this.loadAddress + "/" + this.researchAchievements.supportingMaterials + "?time=" +
                        new Date().getTime(),
                    headers: {
                        isToken: false
                    },
                    method: 'get',
                    timeout: 20000,
                    responseType: 'blob',
                }).then((res) => {
                    ElMessage({
                        showClose: true,
                        message: '请稍等正在下载附件',
                        center: true,
                        type: 'success'
                    })
                    let blob = new Blob([res.data])
                    let fileName = this.researchAchievements.supportingMaterials
                    if (window.navigator.msSaveOrOpenBlob) {
                        navigator.msSaveBlob(blob, fileName)
                    } else {
                        // console.log(3)
                        var link = document.createElement('a')
                        link.href = window.URL.createObjectURL(blob)
                        link.download = fileName
                        link.click()
                        //释放内存
                        window.URL.revokeObjectURL(link.href)
                    }
                }).catch(() => {
                    ElMessage({
                        showClose: true,
                        message: '没有附件',
                        center: true,
                        type: 'error'
                    })
                });
            },
            UpFile(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                if(this.researchAchievements.supportingMaterials!=null) formData.append("fileName", this.researchAchievements.supportingMaterials);
                formData.append("id", this.researchAchievements.id);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: false
                    }
                };
                request.post('/researchAchievements/upFile', formData, config).then((res) => {
                    this.$refs['updataFile'].clearFiles('ready')
                    this.load();
                    this.dialogDealFile = false;
                    ElMessage({
                        showClose: true,
                        message: '上传成功',
                        center: true,
                        type: 'success'
                    })
                });
            },
            dealStatus(row,name){
                request({
                    url: '/researchAchievements/status',
                    headers: {
                        isToken: false
                    },
                    method: 'put',
                    timeout: 20000,
                    data: {
                        id: row.id,
                        status: name
                    }
                }).then(() => {
                    ElMessage({
                        showClose: true,
                        message: '提交成功，状态为'+name,
                        center: true,
                        type: 'success'
                    })
                    this.load();
                });
            },
            getExcelType() {
                request({
                    url: '/static/excel/researchAchievements.xlsx?time=' + new Date().getTime(),
                    headers: {
                        isToken: false
                    },
                    method: 'get',
                    timeout: 20000,
                    responseType: 'blob',
                }).then((res) => {
                    let blob = new Blob([res.data], {
                        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                    })
                    let fileName = "导入科研成果信息" + '.xlsx'
                    if (window.navigator.msSaveOrOpenBlob) {
                        navigator.msSaveBlob(blob, fileName)
                    } else {
                        // console.log(3)
                        var link = document.createElement('a')
                        link.href = window.URL.createObjectURL(blob)
                        link.download = fileName
                        link.click()
                        //释放内存
                        window.URL.revokeObjectURL(link.href)
                    }
                });
            },
            uploadFileExcel(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: true
                    }
                };
                request.post('/researchAchievements/addExcel', formData, config).then(() => {
                    this.$refs['uploadExcel'].clearFiles('ready');
                    this.load();
                    ElMessage({
                        showClose: true,
                        message: '添加成功，如果科研成果信息存在则不能填加，出现冲突请联系管理员',
                        center: true,
                        type: 'success'
                    })
                    this.dialogExcel = false;
                }).catch(()=>{
                     this.$refs['uploadExcel'].clearFiles('ready');
                });
            
            },
        },
        created() {
            this.load();
        },
        setup() {
            return {
                UploadFilled,
                InfoFilled 
            }
        }
    }
</script>

<style scoped>

</style>
